<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    {include file="public/header" /}
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">分类管理</a>
        <a href="">分类列表</a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so layui-form-pane">
          <input class="layui-input" id="cateName" placeholder="分类名" name="cate_name">
          <button class="layui-btn"  type="button" onclick="addGroup()"><i class="layui-icon"></i>增加</button>
        </form>
      </div>
      <table class="layui-table layui-form">
        <thead>
          <tr>
            <th width="70">ID</th>
            <th>栏目名</th>
            <th width="300">操作</th>
        </thead>
        <tbody class="x-cate">
        {foreach name="data" id="vo"}
          <tr>
            <td>{$vo.id}</td>
            <td>
              {$vo.name}
            </td>
            <td class="td-manage">
              <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('编辑','{:url(\'group/updateGroup\',[\'id\'=>$vo.id])}',600,400)" ><i class="layui-icon">&#xe642;</i>编辑</button>
              <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick='member_del(this,"{$vo.id}")' href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
            </td>
          </tr>
        {/foreach}
        </tbody>
      </table>
      <div class="page">
        <div>
          {$page|raw}
        </div>
      </div>
    </div>
    <style type="text/css">
      
    </style>
    <script>
      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              $.ajax({
                  url:"{:url('group/deleteGroup')}",
                  type:'post',
                  dataType:"json",
                  data:{
                      id:id
                  },
                  success:function(data){
                      data = JSON.parse(data);
                      if(data.status == 1){
                          //发异步删除数据
                          $(obj).parents("tr").remove();
                          layer.msg('已删除!',{icon:1,time:1000});
                      }else{
                          layer.msg('删除失败!',{icon:2,time:1000});
                      }
                  }
              });
          });
      }

      function addGroup() {
          var cateName = $('#cateName').val();
          $.ajax({
              url:"{:url('group/addGroup')}",
              type:'post',
              dataType:"json",
              data:{
                  cateName:cateName
              },
              success:function(data){
                  data = JSON.parse(data);
                  console.log(data);
                  if(data.status == 1){
                      layer.msg('添加分类成功!',{icon:1,time:1000});
                      window.location.reload();
                  }else{
                      layer.msg(data.msg,{icon:2,time:1000});
                  }
              }
          });
      }
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>